﻿using HandyControl.Tools.Extension;
using HW.Application.Share.Events;
using HW.Core.Dialog;
using HW.Core.Ioc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace HW.Application.Menu.Views
{
    /// <summary>
    /// MenuView.xaml 的交互逻辑
    /// </summary>
    public partial class MenuView : UserControl
    {
        
        private DispatcherTimer timer;
        private bool isLongPressing = false;
        public MenuView()
        {
            InitializeComponent();
            timer = new DispatcherTimer();
            timer.Interval = TimeSpan.FromSeconds(4); // 修改为8秒
            timer.Tick += Timer_Tick;

        }

        //长按按钮触发事件
        private void Button_MouseDown(object sender, MouseButtonEventArgs e)
        {
            timer.Start();
        }

        private void Timer_Tick(object sender, EventArgs e)
        {
            isLongPressing = true;
            //PrismProvider.EventAggregator.GetEvent<CloseApplicationEvent>().Publish();
        }

        private void Button_MouseUp(object sender, MouseButtonEventArgs e)
        {
            if (isLongPressing)
            {
                // 已经处理了长按事件，无需隐藏窗口
                isLongPressing = false;
            }
            else
            {
                // 未触发长按事件，隐藏窗口
                PrismProvider.EventAggregator.GetEvent<HideWindowEvent>().Publish();
            }
            timer.Stop();
        }



    }
 }
    
